<?php

namespace App\Admin\Extensions\Form;


use Encore\Admin\Form\Field;

class Simplemde extends Field
{
    protected $view = 'admin::form.editor';

    protected static $css = [
        '/packages/simplemde/dist/simplemde.min.css',
        '/packages/simplemde/src/css/highlight.min.css'
    ];

    protected static $js = [
        '/packages/simplemde/dist/simplemde.min.js',
        '/packages/simplemde/src/js/highlight.min.js'
    ];

    public function render()
    {
        $this->script = <<<EOT

 var showMainSidebar=true;
 var main_sidebar=$('.main-sidebar');
 var simplemde = new SimpleMDE({
                showMainSidebar:true,
                autofocus: true,
                autosave: {
                    enabled: false,
                    delay: 5000,
                    unique_id: "editor01",
                },
                spellChecker: false,
                showIcons: ["code", "table"],
                toolbar:[
                "bold", "italic", "strikethrough", "heading", "code", "quote", "unordered-list",
            "ordered-list", "clean-block", "link", "image", "table", "horizontal-rule", "preview", "side-by-side", "fullscreen", "guide",

                    {
                        name: "uploadImage",//自定义按钮
                        action: function customFunction(editor) {
                            if(showMainSidebar){
                                main_sidebar.hide();
                                showMainSidebar=false;
                            }else{
                                main_sidebar.show();
                                showMainSidebar=true;
                            }
                        },
                        className: "fa fa-star",
                        title: "show left"
                    }
                ],
                renderingConfig:{
                    singleLineBreaks: false,
                    codeSyntaxHighlighting:true
                }
            });
            

EOT;
        return parent::render();

    }
}